/**
 * 使用reachBottom 上拉刷新列表页
 * 
 * */ 
const listMixins = {
	data() {
		return {
			tabList: []
		}
	},
	
	/**
	 * onLoad,	重新定义getList
	 * */ 
	onLoad() {
		const that = this;
		that.tabArr.forEach((ele, index) => {
			let listObj = {
				key: 'tab' + index,
				list: [1, 2],
				page: 1,
				limit: 10,
				noever: false,
				loading: true,
				loadStatus: 'more'
			};
			that.tabList.push(listObj);
		});
		let listObj = that.tabList[that.currentIndex];
		let oldGetList = that.getList;
		that.getList = () => {
			listObj.loadStatus = 'loading';
			oldGetList((arr) => {
				listObj.list = listObj.page === 1 ? arr : listObj.list.concat(arr);
				listObj.loadStatus = arr.length < listObj.limit ? 'noMore' : 'more';
				listObj.noever = (listObj.list.length === 0);
				uni.stopPullDownRefresh();
			});
		}
	},
	
	methods: {
		/**
		 * 上拉刷新处理函数
		 * */ 
		toLowerHandler() {
			const that = this;
			let listObj = that.tabList[that.currentIndex];
			if (listObj.loadStatus !== 'more') return;
			listObj.page ++;
			that.getList();
		},
		
		/**
		 * swiper change
		 * */ 
		changeHandler(e) {
			console.log('e--------------');
			console.log(e);
			console.log(e.detail.current);
			const that = this;
			if (that.currentIndex !== e.detail.current) {
				that.currentIndex = e.detail.current;
				that.getList()
			}
		}
	}
}

export default listMixins;
